package com.zhilianbao.leyaogo.view.dialog;

import android.content.Context;
import android.view.View;
import android.widget.TextView;

import com.bql.materialprogressbar.MaterialProgressBar;
import com.bql.roundview.RoundLinearLayout;
import com.bql.variousdialog.widget.base.BaseDialog;
import com.zhilianbao.leyaogo.R;
import com.zhilianbao.leyaogo.utils.Utils;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * ClassName: ProgressDialog1 <br>
 * Description: 进度对话框<br>
 * Author: Cyarie <br>
 * Created: 2016/11/21 19:23 <br>
 * Update Time：<br>
 * Update Description：<br>
 */
public class LeProgressDialog extends BaseDialog<LeProgressDialog> {


    //    @BindView(R.id.iv_loading)
    //    ImageView mIvLoading;
    @BindView(R.id.loadingProgressBar)
    MaterialProgressBar mMaterialProgressBar;
    @BindView(R.id.tv_loading)
    TextView mTvLoading;
    @BindView(R.id.rl_content)
    RoundLinearLayout mRoundLinearLayout;
    //    private AnimationDrawable mAnimationDrawable;

    public LeProgressDialog(Context context) {
        super(context);
    }

    @Override
    public View onCreateView() {
        widthScale(0f);
        View view = View.inflate(mContext, R.layout.dialog_le_progress, null);
        ButterKnife.bind(this, view);
        //        view.setBackgroundDrawable(
        //                CornerUtils.cornerDrawable(Color.parseColor("#ececec"), dp2px(6)));
        return view;
    }

    @Override
    public void setUiBeforeShow() {
        getWindow().setDimAmount(0.25f);
        setCanceledOnTouchOutside(false);
        //        mIvLoading.setBackgroundResource(R.drawable.loading_more);
        //        mAnimationDrawable = (AnimationDrawable) mIvLoading.getBackground();
        //        mAnimationDrawable.mutate();
        //        mAnimationDrawable.start();

    }

    public void setPadding() {
        if (mRoundLinearLayout != null) {
            mRoundLinearLayout.setPadding(Utils.dp2px(20), Utils.dp2px(15), Utils.dp2px(20), Utils.dp2px(15));
        }
    }

    public void setPaddingWithouotText() {
        if (mRoundLinearLayout != null) {
            mRoundLinearLayout.setPadding(Utils.dp2px(25), Utils.dp2px(25), Utils.dp2px(25), Utils.dp2px(25));
        }
    }


    public void showText(String text) {
        if (mTvLoading != null) {
            mTvLoading.setVisibility(View.VISIBLE);
            mTvLoading.setText(text);
        }
    }

    public void hideText() {
        if (mTvLoading != null) {
            mTvLoading.setVisibility(View.GONE);
        }
    }

    @Override
    public void onDetachedFromWindow() {
        super.onDetachedFromWindow();
        //        if (mAnimationDrawable != null)
        //            mAnimationDrawable.stop();
        if (mMaterialProgressBar != null) {
            mMaterialProgressBar.cancel();
            mMaterialProgressBar = null;
        }
    }

    //重写系统返回键处理
    @Override
    public void onBackPressed() {
        if (isShowing()) {
            return;
        }
        super.onBackPressed();
    }

    public void cancelProgressBar() {
        if (mMaterialProgressBar != null) {
            mMaterialProgressBar.cancel();
            mMaterialProgressBar = null;
        }
    }
}
